using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Services;
using Web.Core;

namespace AsmxData
{
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class AdminsHandler : System.Web.Services.WebService
    {
        /// 
        [WebMethod]
        public string getList(string injson)
        {
		    JsonFormat jsf = new JsonFormat(injson);
		    if (!Authority.CheckAuthOnAsmx("AdminsHandler.getList",jsf.GetValue("authid"), jsf.GetValue("authstr"), true))
			  return "{\"result\":\"-1\"}";
            int pagesize = Int16.Parse(jsf.GetValue("rows"));
            int currentpage = Int16.Parse(jsf.GetValue("page"));
            PageInfo pi = new PageInfo();
            pi.PageSize = pagesize;
            pi.PageIndex = currentpage;
    		Model.Admins mdl = new Model.Admins();
        
            PageList<Model.Admins> lst = new BLL.Admins().GetPageList(pi, mdl);
            string json = "{\"total\":" + pi.RecordCount.ToString()+",\"rows";
            json = Newtonsoft.Json.JavaScriptConvert.SerializeObject(lst).Replace("{\"List", json);
			return json;
        }

        /// 
        [WebMethod]
        public string getOne(string injson)
        {
		    JsonFormat jsf = new JsonFormat(injson);
		    if (!Authority.CheckAuthOnAsmx("AdminsHandler.getOne",jsf.GetValue("authid"), jsf.GetValue("authstr"), true))
			  return "{\"result\":\"-1\"}";
            int? id = BLL.BLHelper.GetInt(jsf.GetValue("id"));
	    	Model.Admins wheremdl = new Model.Admins();
    		wheremdl.AdminId = id;
            Model.Admins mdl = new BLL.Admins().GetModel(wheremdl);
            string json = "\"result\":{0},\"model\":{1}";
            if (mdl == null)
                json = String.Format(json, 0, "{}");
            else
                json = String.Format(json, 1, Newtonsoft.Json.JavaScriptConvert.SerializeObject(mdl));
            return "{" + json + "}";
        }

        /// 
        [WebMethod]
        public string AddOne(string injson)
        {
		    JsonFormat jsf = new JsonFormat(injson);
		    if (!Authority.CheckAuthOnAsmx("AdminsHandler.AddOne",jsf.GetValue("authid"), jsf.GetValue("authstr"), true))
			  return "{\"result\":\"-1\"}";
            Model.Admins mdl = new Model.Admins();
	
            mdl.Account = BLL.BLHelper.GetString(jsf.GetValue("Account"));
            mdl.Pass = BLL.BLHelper.GetString(jsf.GetValue("Pass"));
            mdl.ContentInfo = BLL.BLHelper.GetString(jsf.GetValue("ContentInfo"));
            mdl.AdminType = BLL.BLHelper.GetString(jsf.GetValue("AdminType"));
            mdl.AdminPower = BLL.BLHelper.GetString(jsf.GetValue("AdminPower"));
            mdl.NickName = BLL.BLHelper.GetString(jsf.GetValue("NickName"));
            mdl.RealName = BLL.BLHelper.GetString(jsf.GetValue("RealName"));
            mdl.FaceId = BLL.BLHelper.GetString(jsf.GetValue("FaceId"));
            mdl.Aeg = BLL.BLHelper.GetInt(jsf.GetValue("Aeg"));
            mdl.IsClose = BLL.BLHelper.GetBool(jsf.GetValue("IsClose"));
            mdl.SessionKey = BLL.BLHelper.GetString(jsf.GetValue("SessionKey"));
            mdl.LastIP = BLL.BLHelper.GetString(jsf.GetValue("LastIP"));
            mdl.LastTime = BLL.BLHelper.GetString(jsf.GetValue("LastTime"));
            mdl.dteErrs = BLL.BLHelper.GetDateTime(jsf.GetValue("dteErrs"));
            mdl.intErr = BLL.BLHelper.GetInt(jsf.GetValue("intErr"));
            mdl.bitlock = BLL.BLHelper.GetBool(jsf.GetValue("bitlock"));
            new BLL.Admins().Add(mdl);
            return "{\"result\":\"1\"}";
        }

        /// 
        [WebMethod]
        public string RemoveOne(string injson)
        {
		    JsonFormat jsf = new JsonFormat(injson);
		    if (!Authority.CheckAuthOnAsmx("AdminsHandler.RemoveOne",jsf.GetValue("authid"), jsf.GetValue("authstr"), true))
			  return "{\"result\":\"-1\"}";
            int? id = BLL.BLHelper.GetInt(jsf.GetValue("id"));
            Model.Admins wheremdl = new Model.Admins();
	    	wheremdl.AdminId = id;
	    	new BLL.Admins().Delete(wheremdl);
	    	return "{\"result\":\"1\"}";
        }

        /// 
        [WebMethod]
        public string UpdataOne(string injson)
        {
		    JsonFormat jsf = new JsonFormat(injson);
		    if (!Authority.CheckAuthOnAsmx("AdminsHandler.UpdataOne",jsf.GetValue("authid"), jsf.GetValue("authstr"), true))
			  return "{\"result\":\"-1\"}";
            Model.Admins setmdl = new Model.Admins();
	    	Model.Admins wheremdl = new Model.Admins();
	
            setmdl.AdminId = BLL.BLHelper.GetInt(jsf.GetValue("AdminId"));
            setmdl.Account = BLL.BLHelper.GetString(jsf.GetValue("Account"));
            setmdl.Pass = BLL.BLHelper.GetString(jsf.GetValue("Pass"));
            setmdl.ContentInfo = BLL.BLHelper.GetString(jsf.GetValue("ContentInfo"));
            setmdl.AdminType = BLL.BLHelper.GetString(jsf.GetValue("AdminType"));
            setmdl.AdminPower = BLL.BLHelper.GetString(jsf.GetValue("AdminPower"));
            setmdl.NickName = BLL.BLHelper.GetString(jsf.GetValue("NickName"));
            setmdl.RealName = BLL.BLHelper.GetString(jsf.GetValue("RealName"));
            setmdl.FaceId = BLL.BLHelper.GetString(jsf.GetValue("FaceId"));
            setmdl.Aeg = BLL.BLHelper.GetInt(jsf.GetValue("Aeg"));
            setmdl.IsClose = BLL.BLHelper.GetBool(jsf.GetValue("IsClose"));
            setmdl.SessionKey = BLL.BLHelper.GetString(jsf.GetValue("SessionKey"));
            setmdl.LastIP = BLL.BLHelper.GetString(jsf.GetValue("LastIP"));
            setmdl.LastTime = BLL.BLHelper.GetString(jsf.GetValue("LastTime"));
            setmdl.dteErrs = BLL.BLHelper.GetDateTime(jsf.GetValue("dteErrs"));
            setmdl.intErr = BLL.BLHelper.GetInt(jsf.GetValue("intErr"));
            setmdl.bitlock = BLL.BLHelper.GetBool(jsf.GetValue("bitlock"));

            new BLL.Admins().Update(setmdl, wheremdl);
            return "{\"result\":\"1\"}";
        }
    }
}
  